package org.tio.sitexxx.web.server.controller.stat;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.http.common.HttpRequest;
import org.tio.http.server.annotation.RequestPath;
import org.tio.sitexxx.service.service.stat.StatService;
import org.tio.utils.resp.Resp;

import com.jfinal.plugin.activerecord.Record;

/**
 * @author tanyaowu
 * 2016年6月29日 下午7:53:59
 */
@RequestPath(value = "/stat")
public class StatController {
	private static Logger log = LoggerFactory.getLogger(StatController.class);

	/**
	 * @param args
	 * @author tanyaowu
	 */
	public static void main(String[] args) {
		log.info("");
	}

	/**
	 * -- 按天统计页面的访问量
		---------------------------
		--     d              path        count
		-- 2018-04-16   /case/index.html	 24
		-- 2018-04-17   /case/index.html	 109
		-- 2018-04-17   /doc/index.html	     18
		-- 2018-04-16   /doc/index.html	     97
		---------------------------
	 * @param days
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestPath(value = "/requestCountByDay")
	public Resp requestCountByDay(Integer days, HttpRequest request) throws Exception {
		List<Record> list = StatService.me.requestCountByDay(days);

		return Resp.ok(list);
	}

	/**
	 * -- 按天统计不同的ip数
		---------------------------
		--    d         |  count
		-- 2018-04-16	|  35
		-- 2018-04-17	|  222
		---------------------------
	 * @param days
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequestPath(value = "/ipCountByDay")
	public Resp ipCountByDay(Integer days, HttpRequest request) throws Exception {
		List<Record> list = StatService.me.ipCountByDay(days);
		return Resp.ok(list);
	}

	/**
	 * -- 按省统计点击量
		---------------------------------------------
		--  hitcount | ipcount      |  province
		--  6565     |   545	    |  浙江省
		--  5443     |   434	    |  湖南省
		---------------------------------------------
	 * @param days
	 * @param request
	 * @return
	 */
	@RequestPath(value = "/statIpAndHitsByProvince")
	public Resp statIpAndHitsByProvince(Integer days, HttpRequest request) throws Exception {
		List<Record> list = StatService.me.statIpAndHitsByProvince(days);
		return Resp.ok(list);
	}

	/**
	 *
	 * @author tanyaowu
	 */
	public StatController() {
	}
}
